package net.yambal.air.util
{
    public class YambalStringUtility
    {
        public function YambalStringUtility(){
        }
        
        public static function nullComv(s:String, ifEmptyThen:String = null):String{
            if(s){
                s = trim(s);
                if(s.length > 0){
                    return s;
                }
            }
            
            return ifEmptyThen;
        }
        
        public static function toNumver(s:String):Number{
            s = nullComv(s);
            if(s){
                return Number(s);
            }
            return NaN;
        }
        
        public static function trim (str:String):String{
            var regexHead:RegExp = new RegExp('^[ \n\r]*');
            var regexFoot:RegExp = new RegExp('[ \n\r]*$');
            var regexHeadZ:RegExp = new RegExp('^[　\n\r]*');
            var regexFootZ:RegExp = new RegExp('[　\n\r]*$');
            
            return str.replace(regexHead, '').replace(regexFoot, '').replace(regexHeadZ, '').replace(regexFootZ, '');
        }
    }
}